<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style> 
    .ad {
      width: 100px;
      height: 100px;
      background-color: red;
    }
  </style>
</head>
<body>
  <div class="ad">我是广告</div>
  <button>点击关闭广告</button>
  <script>
    const btn = document.querySelector("button");
    const ad = document.querySelector(".ad");
    // DOM L0
    btn.onclick = function() {
      console.log("111111111111");
      ad.style.display = "none";
    }
    // 可以覆盖
    btn.onclick = function() {
      console.log("222222222222");
      ad.style.display = "none";
    }
    // DOM L2 推荐
    btn.addEventListener("click", (e) => {
      // e是事件对象，包含事件的详细信息
      console.log("e----------",e);
      ad.style.display = "none";
    });
    // 可以添加多个，不会覆盖
    btn.addEventListener("click", () => {
      console.log("444444444444");
      ad.style.display = "none";
    });

  </script>
</body>
</html>